<template>
	<view class="loginForget">
		<view class="loginForgetMain">
			<view class="loginForgetLi">
				<view class="loginForgetLiL">
					原手机号
				</view>
				<view class="loginForgetLiR">
					<input type="text" v-model="oldphone"placeholder-class="inputplace" placeholder="请输入原手机号" value="" />
				</view>
			</view>
			<view class="loginForgetLi">
				<view class="loginForgetLiL">
					新手机号
				</view>
				<view class="loginForgetLiR">
					<input type="text" v-model="phone"placeholder-class="inputplace" placeholder="请输入手机号码" value="" />
					<text @click="cli_sendSMS" class="loginForgetLiRYzm" v-if="show_yzm_two">获取验证码</text>
					<text class="loginForgetLiRYzm" v-else>{{yzm_time}}</text>
				</view>
			</view>
			<view class="loginForgetLi">
				<view class="loginForgetLiL">
					验证码
				</view>
				<view class="loginForgetLiR">
					<input type="number" v-model="yzCode"placeholder-class="inputplace" placeholder="请输入验证码" value="" />
				</view>
			</view>
			
		</view>
		<view class="loginForgetBtn" @click="cli_btn">
			确认修改
		</view>
	</view>
</template>

<script>
	import allapi from '../../api/index.js'
	export default {
		data() {
			return {
				agentId: uni.getStorageSync('agentId'),
				show_yzm_two: true,
				yzm_time: 60,
				phone: '',
				oldphone: '',
				yzCode: '',
			}
		},
		methods: {
			// 发送短信
			cli_sendSMS() {
				let re = /^1\d{10}$/
				let phone = this.phone
				if (re.test(phone)) {
					this.sendSMS()
					this.show_yzm_two = false
					let time = this.yzm_time
					let _that = this
					let gettime = setInterval(function() {
						time--
						// console.log(time);
						_that.yzm_time = time
						if (time == 0) {
							clearInterval(gettime)
							_that.yzm_time = 10
							_that.show_yzm_two = true
						}
					}, 1000)
				}else {
					uni.showToast({
						title: '请先输入正确的手机号',
						icon: 'none'
					})
				}
			},
			sendSMS() {
				uni.request({
					url: allapi.sendSMS,
					data: {
						phone: this.phone,
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						});
					}
				})
			},
			// 点击确认修改
			cli_btn () {
				let oldphone = this.oldphone
				let phone = this.phone
				let yzCode = this.yzCode
				if (!oldphone) {
					uni.showToast({
						title: '请先输入原手机号',
						icon: 'none'
					})
				}else if (!phone) {
					uni.showToast({
						title: '请先输入新手机号',
						icon: 'none'
					})
				}else if (!yzCode) {
					uni.showToast({
						title: '请先输入验证码',
						icon: 'none'
					})
				}else {
					this.forgetAgentPassword()
				}
			},
			forgetAgentPassword () {
				uni.request({
					url: allapi.updatePhone,
					data: {
						phone: this.phone,
						yzCode: this.yzCode,
						agentId: this.agentId
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if (res.data.code == 0) {
							setTimeout(function () {
								uni.navigateBack()
							},1000)
						}
					}
				})
			},
		}
	}
</script>

<style scoped>
	.loginForget {
		background: #FFFFFF;
		position: absolute;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.loginForgetMain {
		flex: 1;
		padding: 0 32rpx;
	}

	.loginForgetLi {
		display: flex;
		height: 96rpx;
		align-items: center;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.loginForgetLiL {
		width: 120rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #666666;
	}

	.loginForgetLiR {
		flex: 1;
		margin-left: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.loginForgetLiRYzm {
		width: 152rpx;
		height: 56rpx;
		line-height: 56rpx;
		text-align: center;
		background: #F2F2F2;
		border-radius: 8rpx;
		font-size: 24rpx;
		color: #28CD50;
		font-weight: 400;
	}

	.loginForgetBtn {
		margin: 40rpx;
		height: 92rpx;
		line-height: 92rpx;
		text-align: center;
		background: linear-gradient(90deg, #2ACE52 0%, #1DC248 100%);
		border-radius: 46rpx;
		font-size: 36rpx;
		color: #FFFFFF;
	}
</style>
